<?php
namespace app\common\model;
use think\Model;
class Codelog extends Model{

    public function  checkCode($mobile){
        $res=$this->where(array('mobile'=>$mobile))->find();
        if($res){
            return true;
        }else{
            return false;
        }
    }

    //增加用户验证码
    public function addMsgCode($mobile,$code,$type){
        $data=[
            'mobile'=>$mobile,
            'code'=>$code,
            'code_type'=>$type,
            'add_time'=>time()
        ];
        $res=$this->insert($data);
        if($res){
            return true;
        }else{
            return false;
        }
    }
    //判断是否存在有效验证码
    public function hasCode($mobile,$code_type){
        $where=[
            'mobile'=>$mobile,
            'code_type'=>$code_type,
            'status'=>0,
            'add_time'=>array('gt',time()-60),
        ];
        $this->where(array('add_time'=>array('lt',time()-60),'mobile'=>$mobile,'code_type'=>$code_type,'status'=>0))->update(['status'=>1]);
        $res=$this->where($where)->find();
        return $res;

    }


}